package com.hotelvip.controller;


import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hotelvip.common.utils.JSONResult;
import com.hotelvip.entity.SysMenu;
import com.hotelvip.service.SysMenuService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;


@RestController
@Api(basePath = "/sys/menu/",tags = "菜单模块")
@RequestMapping("/sys/menu/")
public class SysMenuController {

	@Autowired
	private SysMenuService sysMenuService;
	@ApiOperation(value = "添加菜单",httpMethod = "POST")
	@RequestMapping("doSaveObject")
	public JSONResult doSaveObject(@RequestBody SysMenu entity) {
		sysMenuService.saveObject(entity);
		return JSONResult.ok("save ok");
	}
	@ApiOperation(value = "更新菜单",httpMethod = "PUT")
	@RequestMapping("doUpdateObject")
	public JSONResult doUpdateObject(@RequestBody SysMenu entity) {
		sysMenuService.updateObject(entity);
		return JSONResult.ok("update ok");
	}

	@ApiOperation(value = "删除菜单",httpMethod = "DELETE")
	@RequestMapping("doDeleteObject")
	public JSONResult doDeleleObject(Integer id) {
		sysMenuService.deleteObject(id);
		return JSONResult.ok("delete ok");
	}
	@ApiOperation(value = "查看菜单树列表",httpMethod = "GET")
	@RequestMapping("doFindZMenuNodes")
	public JSONResult doFindZtreeMenuNodes() {
		return JSONResult.ok(sysMenuService.findZtreeMenuNodes());
	}
	@ApiOperation(value = "查看菜单列表",httpMethod = "GET")
	@RequestMapping("doFindObjects/{pageNum}/{pageSize}")
	public JSONResult doFindObjects(@PathVariable("pageNum") Integer pageNum,
									@PathVariable("pageSize") Integer pageSize) {
		PageHelper.startPage(pageNum, pageSize);
		List<Map<String, Object>> menus = sysMenuService.findObjects();
		PageInfo<Map<String, Object>> menusPageInfo = new PageInfo<>(menus);
		return JSONResult.ok(menusPageInfo);
	}
	
}


